<template>
	<view class="body">
		<view class="code" @click="code()">
			扫描学生二维码
		</view>
		<view>
				<radio-group @change="chan">	
					<label v-for="item in radioGroup" :key="item">
						<radio :value="item" :checked="item==activeRadio" />{{item}}
					</label>
				</radio-group>
			</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		onLoad() {
			
		},
		methods: {
			async code(){
				// #ifndef H5
				uni.scanCode({
				    success:async (res)=> {
				        console.log('条码类型：' + res.scanType);
				        console.log('条码内容：' + res.result);
						if(res.result){
							await this.Decrypt(res.result)
							// await this.Task()
						}
				    }
				});
				// #endif
				// #ifdef H5
				uni.showToast({
					title:'请在微信小程序打开',
					icon:'none'
				})
				// #endif
				
			},
			Decrypt(result){
				return new Promise((resolve, reject) => {
					uni.request({
						url: this.$httpUrl + '/QrCodeProc/Decrypt',
						// POST/GET
						method: 'GET',
						data: {
							encrypt:result
						},
						success: success => {
							console.log("二维码扫码获取数据返回的", success.data);
							console.log(success.data.code);
							let studentId=success.data.data.studentId;
							let recordTime=success.data.data.recordTime;
							resolve(success);
							if(success.data.code===200)
							{
								uni.navigateTo({
									url:'./studentInfo?studentId='+studentId+'&recordTime='+recordTime
								})
							}
						},
						fail: (fail) => {
							reject(fail)
							console.log(fail);
							// 失败回调
						}
					});
				})
				
			},
			
			
			Task(){
				return new Promise((resolve, reject) => {
					var Admindata=uni.getStorageSync('admin');
					console.log(Admindata.admin.processList);
				uni.request({
					url: this.$httpUrl + '/QrCodeProc/CompleteTask',
					// POST/GET
					method: 'POST',
					
					data: {
						studentNo:uni.getStorageSync('admin'),
						processId:'3',
						recordPerson:'小城'
						
					},
					success: success => {
						
						console.log("获取数据返回的", success.data);
						console.log(success.data.code);
						resolve(success);
						
					},
					fail: (fail) => {
						console.log(fail);
						// 失败回调
					}
				});
				})
			}
			
			}
		

	}
</script>

<style>
.body{

	
}
.code{
	width: 350rpx;
	background-color: #007AFF;
	color: #FFFFFF;
	border-radius:50rpx;
	margin: 0px auto;
	text-align: center;
	line-height: 60rpx;
	height: 60rpx;
	margin-top: 500rpx;
}
	
</style>
